/*
 * This file is a modified version of PhotoShare.java (included in haggle source code)
 * */

/*
 * TODO: How do we make sure this gets loaded first
 * */

package com.googlecode.eightqueenshaggle;

import org.haggle.Attribute;
import org.haggle.DataObject;
import org.haggle.Node;

import android.app.Application;
import android.content.res.Configuration;
import android.util.Log;

public class EightQueens extends Application implements org.haggle.EventHandler {

	public static final String LOG_TAG = "EightQueens";
	
	private android.os.Vibrator vibrator = null;
	private long lastNeighborVibrateTime = -1, lastDataObjectVibrateTime = -1;
	
	//all we need in this class is a handle to the haggleconntector
	private HaggleConnector hc = null;
	
	public BoardViewController boardViewControllerHandler=null;
	public VictoryViewController victoryViewControllerHandler=null;
	public SolutionExplorerViewController solutionExplorerViewHandler=null;
	
	public void onConfigurationChanged(Configuration newConfig) {
		// TODO Auto-generated method stub
		super.onConfigurationChanged(newConfig);
	}

	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();

    	Log.d(EightQueens.LOG_TAG, "EightQueens:onCreate(), thread id=" + Thread.currentThread().getId());
    	
    	vibrator = (android.os.Vibrator)getSystemService(VIBRATOR_SERVICE);
    	
    	//haggle connector needs a reference to this app
    	HaggleConnector.eqHandler = this;
    	
    	//set up haggle
		hc=HaggleConnector.getInstance();	
		
		//we register an interest in everything that concerns this application
		Attribute a = new Attribute("puzzleName", "EQclassicalPuzzle", 1);
		HaggleConnector.getInstance().getHaggleHandle().registerInterest(a);
		
	
	}

	public void onLowMemory() {
		// TODO Auto-generated method stub
		super.onLowMemory();
    	Log.d(EightQueens.LOG_TAG, "EightQueens:onLowMemory()");	
	}

	public void onTerminate() {
		// TODO Auto-generated method stub
		super.onTerminate();
    	Log.d(EightQueens.LOG_TAG, "EightQueens:onTerminate()");	
    	hc.finiHaggle();
	}
	

	
	public HaggleConnector getHaggleConnector() {
		return hc;
	}


	

	
	/*TODO: 
	 * These functions are called be the haggleconnector, make them perform the game specific operations
	 */

	public void onInterestListUpdate(Attribute[] interests) {
		// TODO Auto-generated method stub
		
	}


	public void onNeighborUpdate(Node[] neighbors) {
		// TODO Auto-generated method stub
		
	}

	public void onNewDataObject(DataObject obj) {
		// TODO Auto-generated method stub
		
	}

	public void onShutdown(int reason) {
		// TODO Auto-generated method stub
		
	}


	
}
